﻿using System.Text.RegularExpressions;
using System.ComponentModel.DataAnnotations;

namespace PortugueseValidationAttributes
{
    public class PortuguesePostalCodeAttribute : ValidationAttribute
    {
        private const string POSTAL_CODE_PATTERN = @"^\d{4}(-\d{3})?$";

        public override bool IsValid(object value)
        {
            return Regex.IsMatch((string)value, POSTAL_CODE_PATTERN);
        }
    }

    public class PortuguesePhoneAttribute : ValidationAttribute
    {
        private const string PHONE_PATTERN = @"^((00|\+)351)?\d{9}$";

        public override bool IsValid(object value)
        {
            return Regex.IsMatch((string)value, PHONE_PATTERN);
        }
    }

    public class PortugueseVatNumberAttribute : ValidationAttribute
    {
        private const string VAT_PATTERN = @"^\d{9}$";

        public override bool IsValid(object value)
        {
            return Regex.IsMatch((string)value, VAT_PATTERN);
        }
    } 
}
